class OriginCppcrash():

    def __init__(self, perFileData):
        '''
        :param perFileData: origin data of a cppcrash file
        '''
        self.contents = perFileData
        self.path = perFileData[0]
        self.content = perFileData[1]
        self.process_name = self.getProcessName()[0]
        self.pname_status = self.getProcessName()[1]
        self.reason = self.getReason()
        self.so_list = self.getSoList()

    def getProcessName(self):
        '''
        comment: 获取进程名
        :return:
        '''
        for idx in range(len(self.content)):
            curline: str = self.content[idx]
            if curline.startswith('Process name'):
                if curline.strip() in ['Process name', 'Process name:']:
                    nextline: str = self.content[idx + 1]
                    if nextline.startswith('Reason'):
                        return curline, 0
                    else:
                        return curline + nextline, 1
                else:
                    return curline, 1
            else:
                pass
        return '', 0

    def getReason(self):
        for line in self.content:
            curline: str = line
            if curline.startswith('Reason:'):
                return curline
        return None

    def getSoList(self):
        solist = []
        for line in self.content:
            curline: str = line
            if curline.startswith('#'):
                solist.append(line)
        if solist == []:
            # no so
            return None
        else:
            return solist
